import static org.junit.Assert.*;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;


public class VendingMachineItemTest {
    VendingMachineItem Itemnumber1;
    VendingMachineItem Itemnumber2; 
    VendingMachineItem Itemnumber3;
    VendingMachineItem Itemnumber4;
    double Price1;
    double Price2;
    double Price3;
    double Price4;
    VendingMachine myVendingMachine;
	
    @Before
	public void setUp() throws Exception {
    	//adding item here
        //name given to item 1       
    	Itemnumber1 = new VendingMachineItem("Chicken", 4.50);
    	//name given to item 2
    	Itemnumber2 = new VendingMachineItem("Pepsi", 1.25);
    	//name given to item 3
    	Itemnumber3 = new VendingMachineItem("Cake", 2.25);
    	 myVendingMachine = new VendingMachine();
	}

	@After
	public void tearDown() throws Exception {
		Itemnumber1=null;
		Itemnumber2=null;
		Itemnumber3=null;
	}
    //Test to whether the name and price has filled in vending machine
	@Test
	public void testVendingMachineItem() {
		 Itemnumber4 = new VendingMachineItem ( "Pepsi", 1.25);
         assertNotNull( Itemnumber4.getName());
         assertNotNull( Itemnumber4.getPrice());
       //  assertEquals(VendingMachineItem.class, Itemnumber4.getClass());
	}
	// Test whether the price is less than zero and not equal to zero
	@Test(expected= VendingMachineException.class)
	public void testVendingMachineItem2() {
		 Itemnumber4 = new VendingMachineItem("Pepsi", -1.25);
		 assertFalse( Itemnumber4.getPrice() > 0  || Itemnumber4.getPrice() == 0 );
		 	}
	
	
	// Test whether the price is greater  than zero and  equal to zero
	@Test
	public void testVendingMachineItem3() {
		 Itemnumber4 = new VendingMachineItem("Pepsi", 1.25);
		 assertTrue(  Itemnumber4.getPrice() > 0||(Itemnumber4.getPrice() == 0));
		 
	}

     // Test vending machine item constructor for not null object.
          
    @Test
    public void testVendingMachineItem_4() {
            assertNotNull("Pepsi");     
    }
	
	//test to Check when the name is null  
	@Test
	public void testGetName() {
	VendingMachineItem nullName = new VendingMachineItem(null, 2.5);
		assertNull(nullName.getName());   
	}
		
	//to Check whether the actual name of the vending machine is returning or not  
	@Test
	public void testGetName1() {
		 myVendingMachine.addItem( Itemnumber2, VendingMachine.C_CODE);
         String ItemName = myVendingMachine.getItem(VendingMachine.C_CODE).getName();
         assertEquals( Itemnumber2.getName(), ItemName );
	}
	//to check when the price is null
	@Test
	public void testGetPrice() {		 
		 Itemnumber4 = new VendingMachineItem("Pepsi", 0);
		assertEquals(0,  Itemnumber4.getPrice(), .0001);
}
		
//to check whether the actual price of the vending machine is returned
	@Test
	public void testGetPrice1() {
		 
        myVendingMachine.addItem( Itemnumber3, VendingMachine.A_CODE);
        double itemPrice = myVendingMachine.getItem(VendingMachine.A_CODE).getPrice();
        assertEquals( Itemnumber3.getPrice(), itemPrice , 1.50);
       
}


}